import { getRolesByStatusAndIsEnablemenusByUserId,sysgetmenusByUserId,sysgetMenuList,updateAuthorization,roleAuthorization,getRoleByStatusOrCreateByPage } from '@/services/overviewRobots';

export default {
  namespace: 'authorization',

  state: {
   
  },
  effects: {
    *getRolesByStatusAndIsEnablemenusByUserId({ payload, callback }, { call, put }) { // 实体管理 使用中词槽列表
      const response = yield call(getRolesByStatusAndIsEnablemenusByUserId, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *sysgetmenusByUserId({ payload, callback }, { call, put }) { // 实体管理 使用中词槽列表
      const response = yield call(sysgetmenusByUserId, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *sysgetMenuList({ payload, callback }, { call, put }) { // 通过角色id获取功能菜单列表副本
      const response = yield call(sysgetMenuList, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *updateAuthorization({ payload, callback }, { call, put }) { // 编辑角色的权限
      const response = yield call(updateAuthorization, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *roleAuthorization({ payload, callback }, { call, put }) { // 添加角色的权限
      const response = yield call(roleAuthorization, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRoleByStatusOrCreateByPage({ payload, callback }, { call, put }) { // 添加角色的权限
      const response = yield call(getRoleByStatusOrCreateByPage, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchb(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        total:'',
        list:[]
      };
    },
  },
};
